export interface RetResult<T> {
  mod: string;
  ret: T;
  param: any[];
}

export type ModeFuncRet<T> = Promise<RetResult<T>>;
export interface ResultFail {
  Result: "FAIL"; //  | "FAILED"
}

export interface ResultOk {
  Result: "OK"; //  | "SUCCESS"
}
export interface ResultFail2 {
  Result: "FAILED"; //  | "FAILED"
}

export interface ResultOk2 {
  Result: "SUCCESS"; //  | "SUCCESS"
}
export type DeviceStatus =
  | "HEALTHY"
  | "HWERROR"
  | "USERERROR"
  | "OFFLINE"
  | "POWEROFF"
  | "NODEVICE"
  | "BUSY"
  | "FRAUDATTEMPT"
  | "POTENTIALFRAUD";

export interface StateBase {
  StDeviceStatus: DeviceStatus;
}

export type Result<T> = (T & ResultOk) | ResultFail;
export type Result2<T> = (T & ResultOk2) | ResultFail2;
export type ResultSelect<T>= T extends Result2<unknown> ? T : Result<T>;
export type SetNeverOtherType<T, I> = {
  [K in keyof T]: T[K] extends I ? T[K] : never;
};

export type FilterNeverTypeKey<T, I> = {
  [K in keyof T]: I extends T[K] ? K : never;
}[keyof T];

export type GetSomeTypeKey<I, T> = FilterNeverTypeKey<
  SetNeverOtherType<I, T>,
  T
>;
//   type E = GetSomeTypeKey<ModsInstanceTest, Glt|Ime>
//   type F = SetNeverOtherType<ModsInstanceTest, Glt>
export type CallFn<T> = ((param: RetResult<T>) => void) | null;
export const getModeFuncRet = function <T>(
  mod: string,
  ret: T,
  param: any[] = []
): RetResult<T> {
  return {
    mod,
    ret,
    param,
  };
};
